'use strict';

superApp.controller('MainController', function ($scope, $q, AuthService, $cookieStore, $location, $log) {
	$scope.userAuth = {
		username : '',
		fullName : '',
		isConnected : false,
	};

	var userAuthData = $cookieStore.get('userAuthData');

	if (userAuthData != null) {
		$scope.userAuth.username = userAuthData.username;
		$scope.userAuth.fullName = userAuthData.name + ' ' + userAuthData.lastname;
		$scope.userAuth.isConnected = true;
	};
	

	// ---

	$scope.logout = function() {		
		// logout en el backend
		var loqsea = AuthService.session.logout();
		$log.info(loqsea);

		$scope.userAuth = {
			username : '',
			fullName : '',
			isConnected : false,
		};

		$cookieStore.remove('isConnected');
		$cookieStore.remove('userAuthData');

		$log.info('cookies removed');

		$location.path('/login');
	};

});